package com.buyouchina.bean.product;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.compass.annotations.Index;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.compass.annotations.Store;

@Entity
@Searchable
// 通过这个注解,指明该类跟lucene中的document映射
public class Product {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@SearchableId
	private Integer id;

	// 名称
	@SearchableProperty(store = Store.YES, boost = 2, name = "productName")
	private String name;
	// 编号
	@SearchableProperty(store = Store.YES)
	private String code;
	// 计量单位
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private String unit;
	// 数量
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private Double quantity;
	// 价格
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private Double price;
	// 进货价
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private Double purchasePrice;
	// 当前库存数量
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private Double curQuantity;
	// 初始库存数量

	private Double initQuantity;
	// 零售价

	private Double retailPrice;
	// 最低库存数量
	private Double minQuantity;
	// 最高库存数量
	private Double maxQuantity;
	// 批发价
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private Double wholesalePrice;
	// 备注
	@SearchableProperty(index = Index.NO, store = Store.YES)
	private String remark;
	// 操作时间
	@SearchableProperty(format = "yyyy-MM-dd")
	private Date date;
	// 状态(上架/下架)
	private Boolean forSale;

	// 货物分类
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "category_id")
	@SearchableComponent
	private Category category;

	// 店铺id
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "outlets_id")
	private Outlets outlets;

	/**
	 * 	复制一个产品类
	 * */
	public Product(Product product) {
		super();
		this.name = product.getName();
		this.code = product.getCode();
		this.unit = product.getUnit();
		this.quantity = product.getQuantity();
		this.price = product.getPrice();
		this.purchasePrice = product.getPurchasePrice();
		this.curQuantity = product.getCurQuantity();
		this.initQuantity = product.getInitQuantity();
		this.retailPrice = product.getRetailPrice();
		this.minQuantity = product.getMinQuantity();
		this.maxQuantity = product.getMaxQuantity();
		this.wholesalePrice = product.getWholesalePrice();
		this.remark = product.getRemark();
		this.date = product.getDate();
		this.forSale = product.getForSale();
		this.category = product.getCategory();
	}

	public Product() {
		this.forSale = true;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Boolean getForSale() {
		return forSale;
	}

	public void setForSale(Boolean forSale) {
		this.forSale = forSale;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public Double getPurchasePrice() {
		return purchasePrice;
	}

	public void setPurchasePrice(Double purchasePrice) {
		this.purchasePrice = purchasePrice;
	}

	public Double getCurQuantity() {
		return curQuantity;
	}

	public void setCurQuantity(Double curQuantity) {
		this.curQuantity = curQuantity;
	}

	public Double getInitQuantity() {
		return initQuantity;
	}

	public void setInitQuantity(Double initQuantity) {
		this.initQuantity = initQuantity;
	}

	public Double getRetailPrice() {
		return retailPrice;
	}

	public void setRetailPrice(Double retailPrice) {
		this.retailPrice = retailPrice;
	}

	public Double getMinQuantity() {
		return minQuantity;
	}

	public void setMinQuantity(Double minQuantity) {
		this.minQuantity = minQuantity;
	}

	public Double getMaxQuantity() {
		return maxQuantity;
	}

	public void setMaxQuantity(Double maxQuantity) {
		this.maxQuantity = maxQuantity;
	}

	public Double getWholesalePrice() {
		return wholesalePrice;
	}

	public void setWholesalePrice(Double wholesalePrice) {
		this.wholesalePrice = wholesalePrice;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Double getQuantity() {
		return quantity;
	}

	public void setQuantity(Double quantity) {
		this.quantity = quantity;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Outlets getOutlets() {
		return outlets;
	}

	public void setOutlets(Outlets outlets) {
		this.outlets = outlets;
	}

}
